package com.collins.thread.practices.drawLottery;

import java.util.Collections;
import java.util.List;

public class LotteryBox implements Runnable{


    @SuppressWarnings("unchecked")
    @Override
    public void run() {
        while(true){
            synchronized (Host.lock){
                if(Host.lotteries.isEmpty()){
                    // when all lotteries being drew, print all
                    List<Integer> list = Host.dataLocal.get(Thread.currentThread().getName());
                    break;
                }else{
                    Collections.shuffle(Host.lotteries);
                    Host.dataLocal.get(Thread.currentThread().getName())
                            .add(Host.lotteries.remove(0));
                }
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
